package com.ruoyi.web.controller.tool;

import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommonWidth {

    static String tttt = "~。，、＇：∶；?‘’“”〝〞ˆˇ﹕︰﹔﹖﹑·¨….¸;！´？！～—ˉ｜‖＂〃｀@﹫¡¿﹏﹋﹌︴々﹟#﹩$﹠&﹪%*﹡﹢﹦﹤‐￣¯―﹨ˆ˜﹍﹎+=<\u00AD\u00AD＿_-\\ˇ~﹉﹊（）〈〉‹›﹛﹜『』〖〗［］《》〔〕{}「」【】︵︷︿︹︽_﹁﹃︻︶︸﹀︺︾ˉ﹂﹄︼";
    static String enBiaodian = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";

    public static String getStringW(String value,int wide) {
        int valueLength = 0;
        String chinese = "[\u4e00-\u9fa5]";
        String all = "";
        String line = "";
//        String value = new String(myValue.getBytes(), StandardCharsets.UTF_8);
        for (int i = 0; i < value.length(); i++) {
            String temp = value.substring(i, i + 1);
            if (enBiaodian.indexOf(temp)>=0) {
                valueLength += 1;
            }
            else if (temp.matches(chinese)||tttt.indexOf(temp)>=0) {
                valueLength += 2;
            } else {
                valueLength += 1;
            }
            all +=temp;
            line +=temp;

            System.out.print(temp);
            System.out.print(valueLength);

            if (valueLength>=wide) {
                all +="\n";
                valueLength = 0;
            }

            if (i>500) {
                System.out.println("返回字符串长度超过500，退出。");
                all+="......";
                break;
            }
        }
        System.out.println(all);
        return all;
    }

    //判断是否为标点符号
    public static boolean isPunctuation(String str)  {
//        String regEx = "[!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~]";
        String regEx = "[`~☆★!@#$%^&*()+=|{}':;,\\[\\]》·.<>/?~！@#￥%……（）——+|{}【】‘；：”“’。，、？]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        //如果长度为1且能匹配正则表达式
        if (str.length() == 1 && m.matches()) {
            return true;
        }else {
            return false;
        }
    }

    public static void main(String[] args) {
//        String tmp = "防疫须知：这十个方面一定要注意！ 1.要坚持佩戴口罩 2.要注意手部卫生 3.要定期开窗通风 4.要谨慎安排出行 5.要遵守疫情防控规定 6.要减少人员聚集 7.要密切关注疫情信息 8.要养成良好卫生习惯 9.出现可疑症状要早就医 10.要积极接种新冠病毒疫苗";
//        System.out.println(getStringW(tmp,46));
        String tmp = "25.5";
        System.out.println(tmp.split("\\.").length);
        System.out.println(tmp.indexOf("."));
    }
}
